home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-portable.exe / quodlibet-3.3.0-portable / data / bin / dummy_thread.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  5KB  |  158 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Drop-in replacement for the thread module.
  5.  
  6. Meant to be used as a brain-dead substitute so that threaded code does
  7. not need to be rewritten for when the thread module is not present.
  8.  
  9. Suggested usage is::
  10.  
  11.     try:
  12.         import thread
  13.     except ImportError:
  14.         import dummy_thread as thread
  15.  
  16. '''
  17. __all__ = [
  18.     'error',
  19.     'start_new_thread',
  20.     'exit',
  21.     'get_ident',
  22.     'allocate_lock',
  23.     'interrupt_main',
  24.     'LockType']
  25. import traceback as _traceback
  26.  
  27. class error(Exception):
  28.     '''Dummy implementation of thread.error.'''
  29.     
  30.     def __init__(self, *args):
  31.         self.args = args
  32.  
  33.  
  34.  
  35. def start_new_thread(function, args, kwargs = { }):
  36.     '''Dummy implementation of thread.start_new_thread().
  37.  
  38.     Compatibility is maintained by making sure that ``args`` is a
  39.     tuple and ``kwargs`` is a dictionary.  If an exception is raised
  40.     and it is SystemExit (which can be done by thread.exit()) it is
  41.     caught and nothing is done; all other exceptions are printed out
  42.     by using traceback.print_exc().
  43.  
  44.     If the executed function calls interrupt_main the KeyboardInterrupt will be
  45.     raised when the function returns.
  46.  
  47.     '''
  48.     global _main, _interrupt
  49.     if type(args) != type(tuple()):
  50.         raise TypeError('2nd arg must be a tuple')
  51.     if type(kwargs) != type(dict()):
  52.         raise TypeError('3rd arg must be a dict')
  53.     _main = False
  54.     
  55.     try:
  56.         function(*args, **kwargs)
  57.     except SystemExit:
  58.         pass
  59.     except:
  60.         _traceback.print_exc()
  61.  
  62.     _main = True
  63.     if _interrupt:
  64.         _interrupt = False
  65.         raise KeyboardInterrupt
  66.  
  67.  
  68. def exit():
  69.     '''Dummy implementation of thread.exit().'''
  70.     raise SystemExit
  71.  
  72.  
  73. def get_ident():
  74.     '''Dummy implementation of thread.get_ident().
  75.  
  76.     Since this module should only be used when threadmodule is not
  77.     available, it is safe to assume that the current process is the
  78.     only thread.  Thus a constant can be safely returned.
  79.     '''
  80.     return -1
  81.  
  82.  
  83. def allocate_lock():
  84.     '''Dummy implementation of thread.allocate_lock().'''
  85.     return LockType()
  86.  
  87.  
  88. def stack_size(size = None):
  89.     '''Dummy implementation of thread.stack_size().'''
  90.     if size is not None:
  91.         raise error('setting thread stack size not supported')
  92.     return 0
  93.  
  94.  
  95. class LockType(object):
  96.     '''Class implementing dummy implementation of thread.LockType.
  97.  
  98.     Compatibility is maintained by maintaining self.locked_status
  99.     which is a boolean that stores the state of the lock.  Pickling of
  100.     the lock, though, should not be done since if the thread module is
  101.     then used with an unpickled ``lock()`` from here problems could
  102.     occur from this class not having atomic methods.
  103.  
  104.     '''
  105.     
  106.     def __init__(self):
  107.         self.locked_status = False
  108.  
  109.     
  110.     def acquire(self, waitflag = None):
  111.         """Dummy implementation of acquire().
  112.  
  113.         For blocking calls, self.locked_status is automatically set to
  114.         True and returned appropriately based on value of
  115.         ``waitflag``.  If it is non-blocking, then the value is
  116.         actually checked and not set if it is already acquired.  This
  117.         is all done so that threading.Condition's assert statements
  118.         aren't triggered and throw a little fit.
  119.  
  120.         """
  121.         if waitflag is None or waitflag:
  122.             self.locked_status = True
  123.             return True
  124.         if not None.locked_status:
  125.             self.locked_status = True
  126.             return True
  127.         return None
  128.  
  129.     __enter__ = acquire
  130.     
  131.     def __exit__(self, typ, val, tb):
  132.         self.release()
  133.  
  134.     
  135.     def release(self):
  136.         '''Release the dummy lock.'''
  137.         if not self.locked_status:
  138.             raise error
  139.         self.locked_status = False
  140.         return True
  141.  
  142.     
  143.     def locked(self):
  144.         return self.locked_status
  145.  
  146.  
  147. _interrupt = False
  148. _main = True
  149.  
  150. def interrupt_main():
  151.     '''Set _interrupt flag to True to have start_new_thread raise
  152.     KeyboardInterrupt upon exiting.'''
  153.     global _interrupt
  154.     if _main:
  155.         raise KeyboardInterrupt
  156.     _interrupt = True
  157.  
  158.